from django_redis import get_redis_connection


def change_last_score_value(account_username):
    """
    重新设置account_username-last_score的值,使其始终等于播放列表中最后一首歌曲对应的分数
    :param account_username:
    :return:
    """
    redis_client = get_redis_connection("playlist")
    # 获取播放列表中最后一个歌曲的score
    playlist_last_data = redis_client.zrevrange(account_username, 0, 0, True)
    playlist_last_value, playlist_last_score = playlist_last_data[0][0], playlist_last_data[0][1]
    # 获取last_score的值
    last_score_old = redis_client.get(f"{account_username}-last_score")
    if last_score_old != playlist_last_score:
        redis_client.set(f"{account_username}-last_score", int(playlist_last_score))
    return
